import requests
import json
import wlan
from utils import common


wifi = wlan.WLAN()
wifi.connect()

def get_message_data(json_res):
    print(json_res)
    common.print_gc_info()
    if 'errorMsg' in json_res:
        return 'error'
    data = json_res["data"]
    if "message" in data:
        msg = data["message"]
        if "content" in msg:
            return msg["content"]
    return '---'

def POST(request_url, payload, type="json"):
    """HTTP POST"""
    payload = json.dumps(payload).encode("utf8")
    # print(payload)
    response = requests.post(
        request_url, headers={"content-type": "application/json"}, data=payload
    )
    # print(response)
    if type == "raw":
        return response

    json_data = json.loads(response.content)
    return json_data

